package de.gameduell.framework.facebook {
	import de.gameduell.framework.facebook.event.InventoryEvent;
	import de.gameduell.facebook.service.gen.CatalogItem;

	import flash.events.EventDispatcher;

	public class FBBaseInventory extends EventDispatcher {
		private var _inventory:Array;

		public function FBBaseInventory() {
			_inventory = new Array();
		}

		public function addToIventory(aCatalogItem:CatalogItem, count:int = 1):void {
			if(_inventory[aCatalogItem.catalogId] == null) {
				_inventory[aCatalogItem.catalogId] = new Array();
			}
			for(var i:int = 0;i < count;i++) {
				_inventory[aCatalogItem.catalogId].push(aCatalogItem);
			}
			dispatchEvent(new InventoryEvent(InventoryEvent.INVENTORY_ITEM_ADDED, aCatalogItem.catalogId, aCatalogItem.title));
		}

		public function getItemById(aId:int):CatalogItem {
			if(_inventory[aId] != null) {
				if(_inventory[aId].length > 0) {
					return CatalogItem(_inventory[aId].shift());
				}
			}
			return null;
		}
	}
}